package com.huazai;

import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.function.IntBinaryOperator;
import java.util.function.IntConsumer;
import java.util.function.IntPredicate;

/**
 * @author Seon
 * @date 2022/11/21 21:05
 */
@Slf4j
public class ReunionLambda {
    /**
     * 函数式接口，什么是函数式借口呢？
     * 就是只有一个抽象方法的接口。
     * @param args
     */
    public static void main(String[] args) {

//        int result = calculateNum((left, right) -> left + right);

//        printNum((int num) -> num % 2 == 0);

        Integer integer = typeCover(Integer::valueOf);
        foreachArr(number -> System.out.printf(String.valueOf(number)));
        foreachArr(System.out::println);
    }

    public static void foreachArr(IntConsumer consumer) {
        int[] arr = {1,2,3,4,5,6,7,8,9,10};
        for (int i : arr) {
            consumer.accept(i);
        }
    }

    public static <R> R typeCover(Function<String, R> function) {
        String str = "12345";
        R result = function.apply(str);
        return result;
    }

    public static void printNum(IntPredicate predicate) {
        int[] arr = {1,2,3,4,5,6,7,8,9,10};
        for (int i : arr) {
            if (predicate.test(i)) {
                System.out.println(i);
            }
        }
    }



    public static int calculateNum(IntBinaryOperator operator) {
        int a = 10;
        int b = 20;
        return operator.applyAsInt(a, b);
    }


}
